package com.lp.common.util;


import com.lp.user.dto.User;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.text.SimpleDateFormat;
import java.util.Date;

import static com.lp.common.util.DateUtil.PATTERN_yyyy_MM_dd_HH_mm_ss;

public class JacksonUtil {
    private static ObjectMapper mapper = new ObjectMapper();

    static {
        if (mapper == null) {
            mapper = new ObjectMapper();
        }
     mapper.setDateFormat(new SimpleDateFormat(PATTERN_yyyy_MM_dd_HH_mm_ss

   ));
    }

    public static ObjectMapper getInstance() {
        return mapper;
    }

    public static void main(String[] args) throws Exception {
        User u = new User();
        u.setCreatedTime(new Date());
        System.out.println(JacksonUtil.getInstance().writeValueAsString(u));
    }
}
